$(function() {
	initButton();
});
// 页面事件绑定
function initButton() {
	// 跳转到茶旅联盟
	$("#attentionNum").bind('click', function() {
		var price = $("#price").html();
		var landType = $('input[name="calculator1"]:radio:checked').val();
		var teaType = $('input[name="calculator2"]:radio:checked').val();
		var teaCategory ="";
		$('input[name="like1[write]"]:checkbox:checked').each(function(){ 
			teaCategory += $(this).val() + ","; 
		});
		teaCategory = teaCategory.substring(0,teaCategory.length-1);
		if(!checkNull(teaCategory,"请选择所产茶叶类别")){
			return;
		}
		var landArea = $("#landArea").val(); // 土地面积
		if(!checkNullCal(landArea) || !isDouble(landArea)){
			easyAlert("请填写正确的土地面积");
			return;
		}
		var subleasePeriod = $("#subleasePeriod").val(); //转租年限
		if(!checkNullCal(subleasePeriod) || !isInt(subleasePeriod)){
			easyAlert("请填写正确的转租年限");
			return;
		}
		var areaProportion = $('input[name="calculator3"]:radio:checked').val();
		var warrantType = $('input[name="calculator4"]:radio:checked').val();
		var limitedTime = $("#limitedTime").val();
		if(!checkNullCal(limitedTime) || !isInt(limitedTime)){
			easyAlert("请填写正确的权证有效期限");
			return;
		}
		var permissionsType = $('input[name="calculator5"]:radio:checked').val();
		var soilTexture ="";
		$('input[name="like1[read]"]:checkbox:checked').each(function(){ 
			soilTexture += $(this).val() + ","; 
		});
		soilTexture = soilTexture.substring(0,soilTexture.length-1);
		if(!checkNull(soilTexture,"请选择土壤质地")){
			return;
		}
		var soilThickness = $('input[name="calculator6"]:radio:checked').val();
		var landFertility = $('input[name="calculator7"]:radio:checked').val();
		var blockShape = $('input[name="calculator8"]:radio:checked').val();
		var flatness = $('input[name="calculator9"]:radio:checked').val();
		var irrigation = $('input[name="calculator10"]:radio:checked').val();
		var drainage = $('input[name="calculator11"]:radio:checked').val();
		var waterSupply = $('input[name="calculator12"]:radio:checked').val();
		var powerSupply = $('input[name="calculator13"]:radio:checked').val();
		var network = $('input[name="calculator14"]:radio:checked').val();
		var enterRoad = $('input[name="calculator15"]:radio:checked').val();
		var mechanization = $('input[name="calculator16"]:radio:checked').val();
		var subsidiary ="";
		$('input[name="like2[write]"]:checkbox:checked').each(function(){ 
			subsidiary += $(this).val() + ","; 
		});
		subsidiary = subsidiary.substring(0,subsidiary.length-1);
		if(!checkNull(subsidiary,"请选择附属设施")){
			return;
		}
		var complement ="";
		$('input[name="like3[write]"]:checkbox:checked').each(function(){ 
			complement += $(this).val() + ","; 
		});
		complement = complement.substring(0,complement.length-1);
		if(!checkNull(complement,"请选择相关配套")){
			return;
		}
		var airport = $('input[name="calculator17"]:radio:checked').val();
		var highRail = $('input[name="calculator18"]:radio:checked').val();
		var highSpeed = $('input[name="calculator19"]:radio:checked').val();
		var railway = $('input[name="calculator20"]:radio:checked').val();
		var highway = $('input[name="calculator21"]:radio:checked').val();
		var port = $('input[name="calculator22"]:radio:checked').val();
		var landUseStatus ="";
		$('input[name="like4[write]"]:checkbox:checked').each(function(){ 
			landUseStatus += $(this).val() + ","; 
		});
		landUseStatus = landUseStatus.substring(0,landUseStatus.length-1);
		if(!checkNull(landUseStatus,"请选择地块利用现状")){
			return;
		}
		var whatManager ="";
		$('input[name="like5[write]"]:checkbox:checked').each(function(){ 
			whatManager += $(this).val() + ","; 
		});
		whatManager = whatManager.substring(0,whatManager.length-1);
		if(!checkNull(whatManager,"请选择适合何种经营")){
			return;
		}
		var income ="";
		$('input[name="like6[write]"]:checkbox:checked').each(function(){ 
			income += $(this).val() + ","; 
		});
		income = income.substring(0,income.length-1);
		if(!checkNull(income,"请选择主要收入来源")){
			return;
		}
		var laborResources = $('input[name="calculator23"]:radio:checked').val();
		var capitaIncome = $('input[name="calculator24"]:radio:checked').val();
		var subsidy ="";
		$('input[name="like7[write]"]:checkbox:checked').each(function(){ 
			subsidy += $(this).val() + ","; 
		});
		subsidy = subsidy.substring(0,subsidy.length-1);
		if(!checkNull(subsidy,"请选择补贴")){
			return;
		}
		var policy ="";
		$('input[name="like8[write]"]:checkbox:checked').each(function(){ 
			policy += $(this).val() + ","; 
		});
		policy = policy.substring(0,policy.length-1);
		if(!checkNull(policy,"请选择政策")){
			return;
		}
		$.ajax({
			type : "post",
			url : server_url
					+ 'rest/tea/calculator/calculator.do?ran=' + Math.random(),
			dataType : 'json',
			async : true,
			data : {
				price:price,
				landType:landType,
				teaType:teaType,
				teaCategory:teaCategory,
				landArea:landArea,
				subleasePeriod:subleasePeriod,
				areaProportion:areaProportion,
				warrantType:warrantType,
				limitedTime:limitedTime,
				permissionsType:permissionsType,
				soilTexture:soilTexture,
				soilThickness:soilThickness,
				landFertility:landFertility,
				blockShape:blockShape,
				flatness:flatness,
				irrigation:irrigation,
				drainage:drainage,
				waterSupply:waterSupply,
				powerSupply:powerSupply,
				network:network,
				enterRoad:enterRoad,
				mechanization:mechanization,
				subsidiary:subsidiary,
				complement:complement,
				airport:airport,
				highRail:highRail,
				highSpeed:highSpeed,
				railway:railway,
				highway:highway,
				port:port,
				landUseStatus:landUseStatus,
				whatManager:whatManager,
				income:income,
				laborResources:laborResources,
				capitaIncome:capitaIncome,
				subsidy:subsidy,
				policy:policy
			},
			success : function(result) {
				console.log(result);
				if (result.retCode == '0000') {
					$("#total").html(result.data)
				}else{
					showErrorMsg(result.data);
				}
			}
		});
		
		
	});

}

//改变地区，重新根据地区进行过滤
function changeArea(areaP){
	area = areaP;
	if(area == "安徽" || area == "广西" || area == "湖北" || area == "河南" || area == "江西" || area == "四川"){
		$("#price").html("70");
	}else if(area == "福建" || area == "广东" || area == "云南"){
		$("#price").html("100");
	}else if(area == "湖南" || area == "江苏"){
		$("#price").html("80");
	}else if(area == "浙江"){
		$("#price").html("90");
	}else{
		$("#price").html("60");
	}
}